# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class GoldBean_PlayGame(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        time1 = time.time()
        while True:
            if poco("JDCLobbyScene").exists():
                break

            if time.time() - time1 > 5 * 60:
                break

        # try:
        #     poco("tablescene").wait_for_appearance()
        # except:
        #     print("比赛等待界面打开超时")

        # assert_equal(poco("tablescene").exists(), True, "打开房间界面正常")

        # gameLayer = poco("tablescene").child("gamelayer")

        # if not gameLayer.exists():
        #     return True

        # while True:
        #     calllordLayer = gameLayer.child("calllordlayer")
        #     cardopt = gameLayer.child("cardopt")
        #     handcardLayer = gameLayer.offspring("handcardlayer")

        #     if calllordLayer.exists() and calllordLayer.attr("visible"):
        #         # 叫抢地主
        #         try:
        #             n = random.randint(1, 10)
        #             if n % 2 == 0:
        #                 btnCall = calllordLayer.offspring("btn_call")
        #                 if btnCall and btnCall.attr("visible"):
        #                     self.clickButton(btnCall)
        #             else:
        #                 btnNoCall = calllordLayer.offspring("btn_nocall")
        #                 if btnNoCall and btnCall.attr("visible"):
        #                     self.clickButton(btnNoCall)
        #         except:
        #             print("")

        #     if cardopt.exists():
        #         # 首出，出最小一张牌
        #         optCardLayer = cardopt.offspring("opt_card_layer")

        #         isDone = False
        #         try:
        #             if not isDone:
        #                 btnPass = cardopt.offspring("notout_btn")
        #                 btnRemind = cardopt.offspring("remind_btn")
        #                 btnOutCard = cardopt.offspring("out_btn")

        #                 if btnPass.attr("visible") and btnRemind.attr("visible") and btnOutCard.attr("visible"):
        #                     self.clickButton(btnRemind)
        #                     self.clickButton(btnOutCard)

        #                 isDone = True
        #         except:
        #             print("")

        #         try:
        #             if not isDone:
        #                 btnOutCard = cardopt.offspring("out_btn")
        #                 if btnOutCard.attr("visible"):
        #                     allCards = handcardLayer.offspring(
        #                         "<Node | Tag = -1")
        #                     allCards[len(allCards) - 1].click()
        #                     self.clickButton(btnOutCard)

        #                 isDone = True
        #         except:
        #             print("")

        #         try:
        #             if not isDone:
        #                 btnUnable = cardopt.offspring("unable_btn")
        #                 if btnUnable.attr("visible"):
        #                     self.clickButton(btnUnable)

        #                 isDone = True
        #         except:
        #             print("")
        return True
        
_instance = GoldBean_PlayGame()
runTest = _instance.runTest
